package com.unicom.shenzhen.sgip;

import com.cloudhopper.commons.util.windowing.WindowFuture;
import com.unicom.shenzhen.sgip.exception.RecoverablePduException;
import com.unicom.shenzhen.sgip.exception.SgipChannelException;
import com.unicom.shenzhen.sgip.exception.SgipTimeoutException;
import com.unicom.shenzhen.sgip.exception.UnrecoverablePduException;
import com.unicom.shenzhen.sgip.pdu.SgipPduRequest;
import com.unicom.shenzhen.sgip.pdu.SgipPduResponse;
import com.unicom.shenzhen.sgip.pdu.SgipSubmit;
import com.unicom.shenzhen.sgip.pdu.SgipSubmitResp;

/**
 * Created by BR on 17/11/6.
 *
 * @author <a href="mailto:wangjiacheng@szunicom.com">Jiacheng Wang</a>
 */
public interface SgipSession {

	enum State {
		INITIAL, OPEN, BINDING, BOUND, UNBINDING, CLOSED
	}

	boolean isOpen();

	boolean isBinding();

	boolean isBound();

	boolean isUnbinding();

	boolean isClosed();

	SgipSubmitResp submit(
		SgipSubmit request, long timeoutMillis
	) throws RecoverablePduException, UnrecoverablePduException, SgipTimeoutException, SgipChannelException, InterruptedException;

	void unbind(long timeoutMillis);

	void close();

	void close(long timeoutMillis);

	void destroy();

	WindowFuture<Integer, SgipPduRequest, SgipPduResponse> sendRequestPdu(
		SgipPduRequest request, long timeoutMillis, boolean synchronous
	) throws RecoverablePduException, UnrecoverablePduException, SgipTimeoutException, SgipChannelException, InterruptedException;

	void sendResponsePdu(
		SgipPduResponse response
	) throws RecoverablePduException, UnrecoverablePduException, SgipChannelException, InterruptedException;
}
